﻿using Robotics.Race;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ai
{
    public class AiController : Controller
    {
        public AiController()
        {
        }

        bool left = false;
        bool right = false;

		public override void Drive( SensedEnvironment environment, ControlGear gear )
		{
            if (environment.LeftTerrain == SensedEnvironment.TerrainType.Road && environment.RightTerrain == SensedEnvironment.TerrainType.Road)
            {
                gear.Acceleration = 0.6;
            }
            else if (environment.LeftTerrain == SensedEnvironment.TerrainType.Road && environment.RightTerrain == SensedEnvironment.TerrainType.Grass)
            {
                gear.Steering = -1;
                gear.Acceleration = -1;
                left = true;
                right = false;
            }
            else if (environment.LeftTerrain == SensedEnvironment.TerrainType.Grass && environment.RightTerrain == SensedEnvironment.TerrainType.Road)
            {
                gear.Steering = 1;
                gear.Acceleration = -1;
                right = true;
                left = false;
            }
            else
            {
                gear.Acceleration = -1;
                if (left)
                    gear.Steering = -1;
                else
                    gear.Steering = 1;
            }
		}
	}
}
